-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a ChainTipChange
type to await
chain tip changes
#2715
Conversation
`fastmod ChainTipReceiver CurrentChainTip zebra*`
Also includes the following name changes: ``` fastmod CurrentChainTip LatestChainTip zebra* fastmod chain_tip_receiver latest_chain_tip zebra* ```
5836db9
to
cd490cb
Compare
ChainTipChange
type, to await
state best chain tip changesChainTipChange
type to await
chain tip changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks good. The only design related thing that could be discussed is if it would make sense to have only one type. I.e., moving the methods from LatestChainTip
into ChainTipChange
. It has the advantage of being less code and possibly requiring less mental context, but it does have the disadvantage of having two purposes for the same type, which is okay but could lead to increasing the mental context depending on what scenarios it is used. I'm fine either way, I just wanted to bring it up in case it helps.
let PreparedBlock { | ||
block: _, | ||
hash, | ||
height, | ||
new_outputs: _, | ||
transaction_hashes, | ||
} = prepared; | ||
Self { | ||
hash, | ||
height, | ||
transaction_hashes, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: I'm wondering if separating the binding from the construction is a matter of style or if there's some advantage I missed. Like, is this used to be able to capture when new fields are added to PreparedBlock
in the future? Just for comparison, my default approach would be something like:
let PreparedBlock { | |
block: _, | |
hash, | |
height, | |
new_outputs: _, | |
transaction_hashes, | |
} = prepared; | |
Self { | |
hash, | |
height, | |
transaction_hashes, | |
} | |
Self { | |
hash: prepared.hash, | |
height: prepared.height, | |
transaction_hashes: prepared.transaction_hashes, | |
} |
I think it's a matter of style, so there's no need to change it. I'm just curious if there's a reason or if there are certain situations where it's preferable to write the destructuring separately 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used to avoid cloning the Arc
s, which is slightly more expensive due to the atomic reference count.
I've also found it useful to explicitly show all the fields, and show which fields we're dropping.
One more design thing. The Edit: This might need to wrap the |
I deliberately named
Edit: actually, I don't think that would be helpful, because it's conceptually different. |
They're actually quite different types, I'll see if I can update the docs and names to make that clearer. |
Hopefully the code at https://github.com/ZcashFoundation/zebra/pull/2721/files#r700043308 also clarifies this question. |
Motivation
Some tasks need to wait for the state's best chain tip to change.
Solution
ChainTipChange
implementationThis PR is part of ticket #2639, but it doesn't close that ticket.
Review
@jvff can review this PR.
Reviewer Checklist
Follow Up Work
Implement
TipAction::Reset
inChainTipChange
- #2639